
#include "loraAPP2.h"
#include "Arduino.h"



int counter = 0;


void InitLora(){
  // Please set code:Serial.begin(9600)
  Serial.begin(9600);
  Serial.print('\n');
  for (unsigned char i = 0; i < 5; i++)
  {
    Serial.print("========================================");
  }
  Serial.println("\nStart To Initializing Lora Module!");
 ;
  for (unsigned char i = 0; i <200; i++)
  {
    Serial.print("-");
  }
  Serial.print("\n");


  LoRa.setPins(15, 27, 26);
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

}


void getData(){
                     
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
    ledblink();
  }
}




void sendData(){

  Serial.print("Sending packet: ");
  Serial.println(counter);
  LoRa.beginPacket();
  LoRa.print("Hello lora");
  LoRa.print(counter);
  LoRa.endPacket();
  ledblink();
  counter++;
}

void ledblink(){
    digitalWrite(21,0);
    delay(200);
    digitalWrite(21,1);
    delay(200);
}